/*******************************************************************************
 * Copyright (c) 2000, 2009 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.destiny.msglipse.component;

import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Layout;

/**
 * This class provides the layout for SashForm
 * 
 * @see SashForm
 */
public class MySashFormLayout extends Layout {
	protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) {
		return new Point(0, 0);
	}

	protected boolean flushCache(Control control) {
		return true;
	}

	protected void layout(Composite composite, boolean flushCache) {
		MySashForm sashForm = (MySashForm) composite;
		Rectangle area = sashForm.getClientArea();
		if (area.width <= 1 || area.height <= 1)
			return;

		if (sashForm.left == null && sashForm.right == null)
			return;

		if (sashForm.maxControl != null && !sashForm.maxControl.isDisposed()) {
			sashForm.maxControl.setBounds(area);
			return;
		}
		int rw = sashForm.right.getBounds().width;
		sashForm.sash.setBounds(area.width - rw - sashForm. getSashWidth(), area.y, sashForm.getSashWidth(), area.height);
		sashForm.right.setBounds(area.width - rw, area.y, rw, area.height);
		sashForm.left.setBounds(area.x, area.y,
				area.width - sashForm.right.getBounds().width - sashForm.getSashWidth(), area.height);
	}
}
